using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Drawing;
using GameFramework;
using GameEngine;

namespace Projet_X0
{
    public class TerrainMesh : IMesh
    {
        private Texture terrainTexture = null;
        private Sprite terrainSprite = null;
        
        public TerrainMesh()
        {
            
        }

        public override void Init()
        {
            String src = ((Persistance)GameManager.GetServices().persistance).LoadMesh((int)EntityID.Terrain);
            terrainTexture = TextureLoader.FromFile(Display.grfDevice, src);
            terrainSprite = new Sprite(Display.grfDevice);
            GameManager.GetServices().display.SetLimits(new Vector2D(2400, 2400));
        }

        public override void Render()
        {
            Point position = new Point(-(int)GameManager.GetServices().display.GetCameraPosition().GetX() + Display.HRES / 2, -(int)GameManager.GetServices().display.GetCameraPosition().GetY() + Display.VRES / 2);
            terrainSprite.Begin(SpriteFlags.AlphaBlend);
            terrainSprite.Draw2D(terrainTexture, Point.Empty, 0, position, System.Drawing.Color.White.ToArgb());
            terrainSprite.End();
        }

        public override void Terminate()
        {
            terrainSprite.Dispose();
            terrainTexture.Dispose();
        }
    }
}
